﻿<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema"
                xmlns:d="http://schemas.microsoft.com/sharepoint/dsp"
                version="1.0"
                exclude-result-prefixes="xsl msxsl ddwrt"
                xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime"
                xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
                xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:msxsl="urn:schemas-microsoft-com:xslt"
                xmlns:SharePoint="Microsoft.SharePoint.WebControls"
                xmlns:ddwrt2="urn:frontpage:internal">


  <xsl:template match="FieldRef[@FieldType='DotsadStatusField']" mode="PrintFieldWithECB">
    <xsl:param name="thisNode" select="." />
    <xsl:variable name="thisValue" select="$thisNode/@*[name()=current()/@Name]"/>
    <xsl:variable name="url">
      <xsl:choose>
        <xsl:when test="contains($thisValue, ',')">
          <xsl:value-of select="substring-before($thisValue, ',')" />
        </xsl:when>
        <xsl:otherwise>
          <xsl:value-of select="$thisValue" />
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <xsl:variable name="splits">
      <xsl:call-template name="IWURLPLUStokesn">
        <xsl:with-param name="str" select="$thisValue"/>
      </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="WorkflowId">
      <xsl:if test="contains($thisValue, ',')">
        <xsl:call-template name="IWURLPLUSGetPartAtIndex">
          <xsl:with-param name="splits" select="$splits"/>
          <xsl:with-param name="index" select="2"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="RenderjQuery">
      <xsl:if test="contains($thisValue, ',')">
        <xsl:call-template name="IWURLPLUSGetPartAtIndex">
          <xsl:with-param name="splits" select="$splits"/>
          <xsl:with-param name="index" select="3"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="WorkflowStaticName">
      <xsl:if test="contains($thisValue, ',')">
        <xsl:call-template name="IWURLPLUSGetPartAtIndex">
          <xsl:with-param name="splits" select="$splits"/>
          <xsl:with-param name="index" select="4"/>
        </xsl:call-template>
      </xsl:if>
    </xsl:variable>
    <xsl:variable name="desc" select="$thisNode/@*[name()=concat(current()/@Name, '.desc')]" />
    <xsl:choose>
      <xsl:when test="$WorkflowId=''">
        <img border="0">
          <xsl:attribute name="src">/_layouts/images/WARN16.GIF</xsl:attribute>
          <xsl:attribute name="alt">No Workflow set or was added to an existing item.</xsl:attribute>
        </img>         
      </xsl:when>
      <xsl:otherwise>
        <xsl:choose>
          <xsl:when test="$RenderjQuery='True'">
            <script src="/_layouts/Dotsad.WFField/js/wffield.js" />
            <script src="/_layouts/Dotsad.WFField/js/jquery-1.7.1.min.js" />
            <script src="/_layouts/Dotsad.WFField/js/jquery-ui-1.8.18.custom.min.js" />
            <link rel="stylesheet" href="/_layouts/Dotsad.WFField/css/jquery-ui-1.8.18.custom.css"/>
            <a onclick="javascript:GetWFStatus(this,{$thisNode/@ID},&quot;{$List}&quot;,&quot;{$WorkflowId}&quot;,&quot;{$WorkflowStaticName}&quot;);return false;" >
              <img border="0">
                <xsl:attribute name="src">/_layouts/images/hhelp.gif</xsl:attribute>
              </img>
            </a>
          </xsl:when>
          <xsl:otherwise>
            <script src="/_layouts/Dotsad.WFField/js/wffield.js" />
            <a onclick="javascript:GetWFStatus(this,{$thisNode/@ID},&quot;{$List}&quot;,&quot;{$WorkflowId}&quot;,&quot;{$WorkflowStaticName}&quot;);return false;" >
              <img border="0">
                <xsl:attribute name="src">/_layouts/images/hhelp.gif</xsl:attribute>
              </img>
            </a>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <xsl:template name="IWURLPLUSGetPartAtIndex">
    <xsl:param name="splits"/>
    <xsl:param name="index"/>
    <xsl:value-of select="msxsl:node-set($splits)/token[position()=$index]"/>
  </xsl:template>
  <xsl:template name="IWURLPLUStokesn">
    <xsl:param name="str" select="."/>
    <xsl:param name="splitString" select="','"/>
    <xsl:choose>
      <xsl:when test="contains($str,$splitString)">
        <token>
          <xsl:value-of select="substring-before($str,$splitString)"/>
        </token>
        <xsl:call-template name="IWURLPLUStokesn">
          <xsl:with-param name="str"
    select="substring-after($str,$splitString)"/>
          <xsl:with-param name="splitString" select="$splitString"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <token>
          <xsl:value-of select="$str"/>
        </token>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>


